#!/user/bin/env python
# -*- coding: utf-8 -*-
''' 
Author: Sjy
Description: booster 类型选择
'''
__all__= []


import json

try:
    import middleware as M
    QtWidgets, QtGui, QtCore, Signal = M.QtWidgets, M.QtGui, M.QtCore, M.Signal
    from gui.controls import envs 
except:
    print(f"{__file__}:local test!")

class UiSetBoosterType(QtWidgets.QDialog):
    sigOnOk = Signal(dict)
    def __init__(self, parent=None):
        parent = parent or envs.GL.get_value("APP")
        super(UiSetBoosterType, self).__init__(parent)
        self.initUI()
        self.adjustSize()
        self.show()
    def initUI(self):
        self.__ui = envs.UIForm.UiCustomForm(self.__get_ui_config())
        self.__ui._setup_ui(self)
    def __get_ui_config(self) -> json:
        return {
            # "icon": "icon.png", # window icon
            # "objectName": "test", # window objectName
            "layout":{ # window 主布局
                "margin": [10, 10, 10, 10], # window 主布局的 margin
                "space": 10,  # window 主布局的 Space
                # "objectName": "qLayout", # window 主布局的 objectName
            },
            "items":[
                {
                    "type": "select",
                    "key":"boosterType",
                    "typeParams": { # 不同的类型所需要的参数不同，由typeParams来传递
                        "title": "Booster 类型",
                        "hasDefaultOption": True, # 有默认选项
                        "data":[
                            {"title":"主捆绑连接", "value":"主捆绑连接"},
                            {"title":"捆绑连杆", "value":"捆绑连杆"},
                        ]
                    },
                    "styleParams":{ # 控制样式的参数
                        "margin": [0, 0, 0, 0],
                        "space": 10,
                        "labWidth": 100,
                        "minWidth": 400,
                    },
                },
                {},
                {
                    "type": "tools",
                    "typeParams": { # 不同的类型所需要的参数不同，由typeParams来传递
                        "items": [
                            {
                                "title": "确定",
                                "action":lambda: self.__on_ok(),
                            },
                            {
                                "title": "关闭",
                                "action":lambda: self.reject(),
                            }
                        ],
                    },
                    "styleParams":{ # 控制样式的参数
                        "margin": [0, 0, 0, 0],
                        "space": 10,
                    }
                },
            ]
        }
    def set_data(self, data:dict):
        self.__ui.set_data(data)
    def __on_ok(self):
        info = self.__ui._gets()
        data = info.get("data", {})
        curType = data.get("boosterType")
        if not curType:
            return envs.MBox.warning("请选择Booster类型")
        self.accept()
        self.sigOnOk.emit(data)
